package com.shiningstars.tools;

import java.util.Calendar;

import com.shiningstars.general.Utilities;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.widget.DatePicker;
import android.widget.TextView;

public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {

	int id;

	public DatePickerFragment(int id) {
		this.id = id;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		final Calendar c = Calendar.getInstance();
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH);
		int date = c.get(Calendar.DATE);

		return new DatePickerDialog(getActivity(), this, year, month, date);
	}

	@Override
	public void onDateSet(DatePicker view, int year, int month, int date) {
		final TextView dateView = (TextView) getActivity().findViewById(id);
		dateView.setText(Utilities.getDate(date, month, year));
		dateView.requestFocus();
	}
}